Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure variables are set in case enlist_fixture_connections is called #42060

Merged

Conversation

Tonkpils
Copy link
Contributor

Summary

#40384 Introduced a change which broke our tests at GitHub. We call enlist_fixture_connections when loading fixtures.

The current Rails code uses enlist_fixture_connections when the context is run_in_transasction?. However if
enlist_fixture_connections is called outside of that context the code fails since these variables are not defined. This ensures the code can still be executed without side effects.

I wasn't sure how to or whether I should write a test for this since enlist_fixture_connections is a private method so feedback is appreciated.

Other Information

/cc @eugeneius as the original PR author

called

enlist_fixture_connections is currently called within the code when the
context is `run_in_transasction?`. However if
`enlist_fixture_connections` is called outside of that context the code
fails since these variables are not defined. This ensures the code can
still be executed without side effects
@@ -111,12 +111,11 @@ def setup_fixtures(config = ActiveRecord::Base)
@fixture_connections = []
@@already_loaded_fixtures ||= {}
@connection_subscriber = nil
@legacy_saved_pool_configs = Hash.new { |hash, key| hash[key] = {} }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're making changes in here can you condition these or make one instance var? I don't want the legacy one available when we're not in legacy mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I kept the variables separate but made sure they were only defined and used on their respective connection handling logic since it's more explicit and would allow us to just remove the legacy connection block once we remove that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileencodes I had to revert the change to condition these variables since it looks like the tests call out a setup and teardown with different values causing the variable to load values for legacy and then attempt to tear down non-legacy values and vice-versa.

This caused the failures seen here

Error:
--

BasePreventWritesTest::BasePreventWritesLegacyTest#test_preventing_writes_with_multiple_handlers:
--
  | NoMethodError: undefined method `[]' for nil:NilClass
  | /rails/activerecord/lib/active_record/test_fixtures.rb:209:in `block (2 levels) in setup_shared_connection_pool'

Using the same variable causes the same issue.

@eileencodes eileencodes self-assigned this Apr 23, 2021
@eileencodes eileencodes added this to the 7.0 milestone Apr 23, 2021
@Tonkpils Tonkpils force-pushed the tonkpils/fix-enlist-fixture-connections branch from 7195bcf to e088454 Compare April 23, 2021 15:24
@eileencodes eileencodes merged commit ba1ec19 into rails:main Apr 26, 2021
@Tonkpils Tonkpils deleted the tonkpils/fix-enlist-fixture-connections branch April 26, 2021 13:37
rafaelfranca pushed a commit that referenced this pull request Jun 22, 2021
…onnections

Ensure variables are set in case enlist_fixture_connections is called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants